package com.app.Activity;

import java.util.ArrayList;

import com.app.Adapter.RuleAdapter;
import com.app.Controller.ReadWriteFileController;
import com.app.PhanQuyen.Quyen;
import com.app.RowDTO.RuleRowDTO;

import ReadWriteXML.ReadXML;
import android.R.xml;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ListView;
import android.widget.TextView;
import app.com.ModuleRole.R;

public class frmDanhSachRule extends Activity {
	ListView lvDanhSachRule;
	Button btnChapNhan;
	Button btnHuyBo;
	TextView txtCount;
	public ArrayList<RuleRowDTO> data;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_danh_sach_rule);
		lvDanhSachRule = (ListView) findViewById(R.id.lvDanhSachRule);
		btnChapNhan = (Button) findViewById(R.id.btnChapNhan);
		btnHuyBo = (Button) findViewById(R.id.btnHuyBo);
		txtCount = (TextView) findViewById(R.id.txtCountSelected);
		fillListView();
	}

	public void fillListView() {

		ArrayList<Quyen> ruleList = ReadWriteFileController.readRule(ReadWriteFileController.RULE_BASE_PATH);

		data = new ArrayList<RuleRowDTO>();
		for (Quyen rule : ruleList) {

			RuleRowDTO row = new RuleRowDTO();
			row.rule = rule;
			row.check = false;
			data.add(row);
		}
		RuleAdapter adapter = new RuleAdapter(this, data);
		lvDanhSachRule.setAdapter(adapter);
		Log.d("Phu", "readQuyen2: " + ruleList.size());
	}

	public void countSelectItem() {
		int n = data.size();
		int count = 0;
		for (int i = 0; i < n; i++) {
			if (data.get(i).check)
				count++;
		}
		txtCount.setText(count + "");
	}
}
